package com.dgut.medicalsystem.jms;

import com.dgut.medicalsystem.config.WebSocketServer;
import com.dgut.medicalsystem.entity.Notice;
import com.dgut.medicalsystem.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class consumer {
    @Autowired
    WebSocketServer webSocketServer;
    @Autowired
    NoticeService noticeService;

    @JmsListener(destination = "medical_notice")
    public void receiving(Notice notice) throws IOException {
        System.out.println("消费者在消费");
        if (noticeService.save(notice))
            WebSocketServer.sendInfo(notice.getDescription(), notice.getOwner().toString());
    }
}
